package com.example.teachingSystem.controller;

import com.example.teachingSystem.pojo.form.exam.AddExamForm;
import com.example.teachingSystem.pojo.form.exam.ExamPageQuery;
import com.example.teachingSystem.pojo.form.exam.UpdateExamForm;
import com.example.teachingSystem.pojo.vo.ExamVo;
import com.example.teachingSystem.service.ExamService;
import com.example.teachingSystem.utils.result.PageResult;
import com.example.teachingSystem.utils.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/exam")
@Tag(name = "考试模块")
public class ExamController {

    @Autowired
    private ExamService examService;

    @PostMapping("/one")
    @Operation(summary = "添加考试", security = {@SecurityRequirement(name = "Authorization")})
    public Result<String> addExam(@RequestBody @Validated AddExamForm addExamForm) {
        return examService.addExam(addExamForm);
    }

    @PutMapping("/one")
    @Operation(summary = "更新考试", security = {@SecurityRequirement(name = "Authorization")})
    public Result<String> updateExam(@RequestBody @Validated
                                    UpdateExamForm updateExamForm) {
        System.out.println("date-----------------"+updateExamForm.getExamDate());
        return examService.updateExam(updateExamForm);
    }

    @DeleteMapping("/one/{id}")
    @Operation(summary = "id删除考试", security = {@SecurityRequirement(name = "Authorization")})
    public Result<String> deleteExam(@PathVariable Long id) {
        return examService.deleteExam(id);
    }


    @GetMapping("/more/stu")
    @Operation(summary = "学生获取考试", security = {@SecurityRequirement(name = "Authorization")})
    public PageResult<ExamVo> getExamPageByStu(ExamPageQuery examPageQuery) {
        return examService.getExamPageByStu(examPageQuery);
    }

    @GetMapping("/more/tea")
    @Operation(summary = "老师获取考试", security = {@SecurityRequirement(name = "Authorization")})
    public PageResult<ExamVo> getExamPageByTea(ExamPageQuery examPageQuery) {
        return examService.getExamPageByTea(examPageQuery);
    }

    @GetMapping("/more")
    @Operation(summary = "管理员获取考试", security = {@SecurityRequirement(name = "Authorization")})
    public PageResult<ExamVo> getAllExamPage(ExamPageQuery examPageQuery) {
        return examService.getAllExamPage(examPageQuery);
    }
}